/**
*
* @author
*
*/
class OpPageFireAgain extends OpPage {

    private _bgSprite: egret.Sprite;
    private _btnSprite: egret.Bitmap;
    private _barSprite: egret.Bitmap;
    private _barContentSprite: egret.Bitmap;
    private _angerIconSprite: egret.Bitmap;
    private _touchEnabled: Boolean = false;

    public constructor() {
        super();

        this._bgSprite = new egret.Sprite();
        this._bgSprite.graphics.beginFill(0x000000,0.7);
        this._bgSprite.graphics.drawRect(0,0,1200,750);
        this._bgSprite.graphics.endFill();
        this._bgSprite.width = 1200;
        this._bgSprite.height = 750;
        this._bgSprite.x = 0;
        this._bgSprite.y = 0;
        this.addChild(this._bgSprite);

        this._btnSprite = new egret.Bitmap();
        this._btnSprite.texture = RES.getRes('page/fire-again-btn.png');
        this._btnSprite.width = 402;
        this._btnSprite.height = 132;
        this._btnSprite.x = 399;
        this._btnSprite.y = 400;
        this.addChild(this._btnSprite);

        this._barSprite = new egret.Bitmap();
        this._barSprite.texture = RES.getRes('page/anger-bar-bg.png');
        this._barSprite.width = 675;
        this._barSprite.height = 50;
        this._barSprite.x = 264;
        this._barSprite.y = 300;
        this.addChild(this._barSprite);

        this._barContentSprite = new egret.Bitmap();
        this._barContentSprite.texture = RES.getRes('page/anger-bar-content.png');
        this._barContentSprite.width = 675;
        this._barContentSprite.height = 50;
        this._barContentSprite.x = 264;
        this._barContentSprite.y = 300;
        var rect: egret.Rectangle = new egret.Rectangle(22,22,628,2);
        this._barContentSprite.scale9Grid = rect;
        this.addChild(this._barContentSprite);

        this._angerIconSprite = new egret.Bitmap();
        this._angerIconSprite.texture = RES.getRes('page/anger-bar-icon.png');
        this._angerIconSprite.width = 87;
        this._angerIconSprite.height = 117;
        this._angerIconSprite.x = 880;
        this._angerIconSprite.y = 240;
        this.addChild(this._angerIconSprite);
    }

    public reset(): void {
        this.alpha = 1;
        this._barContentSprite.width = 75;
        this._angerIconSprite.x = 280;
        this._btnSprite.alpha = 0;
    }

    public play(callback?: Function,context?: any): void {
        egret.Tween.get(this._barContentSprite).to({ width: 675 },1000,egret.Ease.cubicInOut);
        egret.Tween.get(this._angerIconSprite).to({ x: 880 },1000,egret.Ease.cubicInOut).call(function() {
            callback && callback.call(context);
        });
        egret.Tween.get(this._btnSprite).to({ alpha: 1 },1000);
    }

    public enableTouch(): void {
        this._touchEnabled = true;
    }

    public oneTouch(event: egret.TouchEvent): void {
        if(event.stageX > 399 && event.stageX < 801 &&
            event.stageY > 400 && event.stageY < 532) {
                if(this._touchEnabled) {
                    this._touchEnabled = false;
                    EventBus.trigger('OP_FIRE_SECOND');
                }
            }
        }
    }